package com.order.model;

import java.sql.Date;
import java.util.List;
import java.util.Set;

import com.orderdetail.model.Order_detailVO;

public class OrdService {
	
	private OrdDAO_interface dao;
	
	public OrdService() {
		dao = new OrdDAO();
	}
	
	public OrdVO addOrder(String maccount ,Date build_time ,String receiver_name ,String receiver_add ,String receiver_tel ,String receiver_email ,Integer send_method ,Date sendTime ,Integer total ,Integer status ,List<Order_detailVO> ordetails) {
		OrdVO ordVO = new OrdVO();
		
		ordVO.setMaccount(maccount);
		ordVO.setBuild_time(build_time);
		ordVO.setReceiver_name(receiver_name);
		ordVO.setReceiver_add(receiver_add);
		ordVO.setReceiver_tel(receiver_tel);
		ordVO.setReceiver_email(receiver_email);
		ordVO.setSend_method(send_method);
		ordVO.setTotal(total);
		ordVO.setStatus(status);
		Long ordId = dao.insert(ordVO, ordetails);
		ordVO.setOrd_id(ordId);
		
		return ordVO;
	}
	
	public OrdVO changeStatus(Long ordId ,Integer status) {
		OrdVO ordVO = getOneOrd(ordId);
		
		if(ordVO != null) {
			ordVO.setStatus(status);
			dao.updateStatus(ordVO);
		}
		
		return ordVO;
	}
	
	public OrdVO getOneOrd(Long ordId) {
		return dao.findByPrimaryKey(ordId);
	}
	
	public List<OrdVO> getOrdByBuildTime(Date buildTime ,Date buildTime2) {
		return dao.findByBuildDate(buildTime, buildTime2);
	}
	
	public List<OrdVO> getAll() {
		return dao.getAll();
	}
	
	public List<OrdVO> getAllByStatus(Integer status) {
		return dao.getAllByStatus(status);
	}
	
	public Set<Order_detailVO> getOrderDetails(Long ordId) {
		return dao.getOrderDetailByOrdId(ordId);
	}
}
